package com.share.servlet;

import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
一、servlet-mapping映射细节：
    注：* 代表任意字符串
    1、任意：<url-pattern>/*</url-pattern>
    2、有前缀：<url-pattern>/action/*</url-pattern>
    3、有后缀：<url-pattern>*.do</url-pattern>
    4、默认index.jsp：<url-pattern>/</url-pattern>

    5、匹配是有优先级的：从高到低：绝对匹配 --> /开头匹配 --> 扩展名方式匹配

 */
public class Servlet4 extends HttpServlet {

    int i = 1;

    public Servlet4() {
        System.out.println("servlet4----构造方法");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    @SneakyThrows
    protected synchronized void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("servlet4----get方法");
        System.out.println("thread name is " + Thread.currentThread().getName());
        i++;
        Thread.sleep(1000);
        System.out.println("i:"+i);
    }
}
